<!--
 * @Author: your name
 * @Date: 2021-12-22 16:33:58
 * @LastEditTime: 2021-12-23 00:29:13
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \briup_am\am-ui\src\pages\play\race\list.vue
-->
<template>
  <div>
    <el-row>
      <el-col :span="12">
        <el-form :model="params" inline size="small">
          <el-form-item>
            <el-input v-model="params.name"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="queryHandler">搜索</el-button>
          </el-form-item>
        </el-form>
      </el-col>
      <el-col :span="12" style="text-align:right">
        <el-button type="primary" size="small" @click="toAddHandler">录入</el-button>
      </el-col>
    </el-row>,
    <el-table size="small" :data="engineerData.list">
      <el-table-column label="赛事名称" prop="race_name" min-width="200" align="center"></el-table-column>
      <el-table-column label="场地地点" prop="location" width="100" align="center"></el-table-column>
      <el-table-column label="场地经度" prop="latitude" width="100" align="center"></el-table-column>
      <el-table-column label="场地纬度" prop="longitude" width="100" align="center"></el-table-column>
       <el-table-column label="比赛时间" prop="race_time" width="100" align="center"></el-table-column>
      <el-table-column label="报价" prop="offer" width="100" align="center"></el-table-column>
      <el-table-column label="操作" width="100" align="center">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="toEditHandler(scope.row)">修改</el-button>
          <el-button type="text" size="small" @click="toBindHandler(scope.row)">接受</el-button>
        </template></el-table-column>
    </el-table>,
    <el-pagination
      layout="prev, pager, next"
      hide-on-single-page
      :total="+engineerData.total"
      :current-page="+engineerData.page"
      :page-size="+engineerData.pageSize"
      @current-change="pageChangeHandler"
    ></el-pagination>,
    <el-dialog :title="title" :visible.sync="visible">
     
      <el-form :model="form" label-width="100px">

        <el-form-item label="比赛名称" >
          <el-input v-model="form.race_name" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="比赛地点" >
          <el-input v-model="form.location" autocomplete="off"></el-input>
        </el-form-item>
       
        <el-form-item label="比赛时间" >
          <el-input v-model="form.race_time" autocomplete="off"></el-input>
        </el-form-item>,
         <el-form-item label="报价" >
          <el-input v-model="form.offer" autocomplete="off"></el-input>
        </el-form-item>
        
      </el-form>,
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="visible = false">取 消</el-button>
        <el-button size="small" type="primary" @click="submitHandler">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>,
<script>
import {get,postJSON} from '@/utils/request'
export default {
  data(){
    return {
      params:{
        page:1,
        pageSize:10
      },
      title:"",
      visible:false,
      form:{},
      engineerData:{list:[]},
      charges:[],
    }
  },
  mounted() {
    this.loadEngineers();
    this.queryCharges();
  },
  methods:{
    // 绑定设备
    toBindHandler(row){
      this.$router.push({
        path:'/play/race/details',
        query:row
      })
    },
    // 查询区域经理
   
    queryHandler(){
      this.params.page = 1;
      this.loadEngineers();
    },
    submitHandler(){
      let url ="/company/saveOrUpdate"
      postJSON(url,this.form).then(resp => {
        this.$message({type:"success",message:resp.message})
        this.visible = false;
        this.loadEngineers();
      })
    },
    toEditHandler(row){
      this.form = row;
      this.title = "更改比赛公司信息"
      this.visible = true;
    },
    // 加载工程数据
    loadEngineers(){
      let url = "/company/pageQuery";
      get(url,this.params).then(resp => {
        this.engineerData = resp.data;
      })
    },
    pageChangeHandler(page){
      this.params.page = page;
      this.loadEngineers();
    },
    toAddHandler(){
      this.visible = true;
      this.title = "录入比赛公司";
      this.form = {}
    }
  }
}</script>
